//*********************************************************************
//
// Hydra Memory System Model for the MIPSY simulator under SimOS
//
// the Hydra Group, February-July 1996
//
// Header file containing necessary declarations for the simulator's
// objects.
//
// This particular header contains all information pertinent to the
// operation of a latency histogram object.
//
//*********************************************************************

#ifndef __HISTOGRAM_H__
#define __HISTOGRAM_H__

#include "util/Pool.h"
#include <cstdio>

//*********************************************************************
// The Histogram Object
//
// This object maintains a histogram of values that are fed into it,
// and can print it out whenever it is desired.
//*********************************************************************

// Parameters about maximum histogram bar heights and widths
const int peakBarHeight = 56;
const int longestHistogramSize = 128;

class Histogram {
  private:

    // Array storage variable
    int *items;

    // Statistics variables
    const char *name;
    int size, time, totalA, totalB, count, minimum, maximum;

  public:

    // overloaded to force use of CALLOC/FREE
    NEW_DELETE_OPERATORS_H(Histogram,NoSuper);
    // The initializer/destructor pair sets up the histogram.
    // The user should choose a size of the last true bucket
    // of the histogram -- the system will automatically add
    // a "tail" bucket to catch extreme cases.
    Histogram (int _size, const char* _name);
    ~Histogram ();

    // PrintStats prints out the histogram
    void printStats (FILE *output, const char* prefix);
    inline double getTotal () {
        return (1.0e9*totalB + 1.0*totalA);
    }

    // The add function tosses a new entry into the histogram
    void add (int newItem);

    // The multiadd function tosses many copies of an item
    //   into the histogram at once
    void multiAdd (int newItem, int inCount);

    const char* getName () { return name; }

  private:
    static void printBar (int size, double scale, FILE *output, const char* prefix);

};

#endif // __HISTOGRAM_H__
